package com.bdqn.ch03.SZ.sz3.jdk;

import java.lang.reflect.Proxy;

/**
 *
 * MessageDebugJdkProxyFactory
 *
 * 定义代理工厂 使用Proxy 类基于前文定义的代理业务逻辑规则为指定接口动态生成代理对象
 *
 * @aurhor Administrator  whs
 * @since 2024/7/8
 */
public class MessageDebugJdkProxyFactory {
    public static <T> T createMessage(Object target) {

        MessageAgency messageAgency = new MessageAgency();
        messageAgency.setTarget(target);  // 给参数赋值
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), messageAgency);
    }
}
